package com.mes.web.controller.biz;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.mes.common.annotation.Log;
import com.mes.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.SecurityUtils;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.mes.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.biz.domain.BizProductWarehouse;
import com.mes.biz.service.BizProductWarehouseService;

/**
 * 成品仓库档案Controller
 * @author hwg
 * @email hwg
 * @date 2023-04-30
 */
@RestController
@RequestMapping("/biz/bizProductWarehouse")
public class BizProductWarehouseController extends BaseController {

    @Autowired
    private BizProductWarehouseService bizProductWarehouseService;

    /**
     * 查询成品仓库档案列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:list')")
    @GetMapping("/list")
    public R<PageInfo> list(BizProductWarehouse bizProductWarehouse, HttpServletRequest request, HttpServletResponse response) {
        bizProductWarehouse.setPage(new PageDomain(request, response));
        return R.data(bizProductWarehouseService.findPage(bizProductWarehouse));
    }

    /**
     * 获取成品仓库档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:query')")
    @GetMapping(value = "/{id}")
    public R<BizProductWarehouse> detail(@PathVariable("id") String id) {
        return R.data(bizProductWarehouseService.get(id));
    }

    /**
     * 新增成品仓库档案
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:add')")
    @Log(title = "成品仓库档案", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  BizProductWarehouse bizProductWarehouse) {
        bizProductWarehouse.setTenantId(SecurityUtils.getTenantId());
        return R.status(bizProductWarehouseService.save(bizProductWarehouse));
    }

    /**
     * 修改成品仓库档案
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:edit')")
    @Log(title = "成品仓库档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizProductWarehouse bizProductWarehouse) {
        return R.status(bizProductWarehouseService.save(bizProductWarehouse));
    }

    /**
     * 删除成品仓库档案
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:remove')")
    @Log(title = "成品仓库档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizProductWarehouseService.deleteBizProductWarehouseByIds(ids));
    }


    /**
     * 校验位置的唯一性
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:query')")
    @Log(title = "成品仓库档案", businessType = BusinessType.CHECK)
    @GetMapping(value = {"/checkPostionUnique/{postion}/{id}", "/checkPostionUnique/{postion}"})
    public R checkPostionUnique(@NotBlank(message = "位置不允许为空") @PathVariable("postion") String postion, @PathVariable(value = "id", required = false) String id) {
        BizProductWarehouse bizProductWarehouse = new BizProductWarehouse();
        bizProductWarehouse.setPostion(postion);
        bizProductWarehouse.setId(id);
        bizProductWarehouseService.checkPostionUnique(bizProductWarehouse);
        return R.status(Boolean.TRUE);
    }

    /**
     * 导出成品仓库档案列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductWarehouse:export')")
    @Log(title = "成品仓库档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizProductWarehouse bizProductWarehouse) {
        List<BizProductWarehouse> list = bizProductWarehouseService.findList(bizProductWarehouse);
        ExcelUtil<BizProductWarehouse> util = new ExcelUtil<BizProductWarehouse>(BizProductWarehouse.class);
        return util.exportExcel(list, "成品仓库档案数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

    @GetMapping("/appletList")
    public R<List<BizProductWarehouse>> appletList(BizProductWarehouse bizProductWarehouse, HttpServletRequest request, HttpServletResponse response) {
        return R.data(bizProductWarehouseService.findList(bizProductWarehouse));
    }

}
